package com.thyrsus.project.helper;

import javax.servlet.http.HttpServletRequest;

public class URLHelper {

	public static String getURL(String url,HttpServletRequest request) {
		if (SessionHelper.getAttribute(request, Constants.NAVIGATOR_KIND)!=null)
			return (String)SessionHelper.getAttribute(request, Constants.NAVIGATOR_KIND)+url;
		if (isMobile(request)) {
			SessionHelper.setAttribute(request, Constants.NAVIGATOR_KIND,"/mobile");
			return "/mobile"+url;
		} else {
			SessionHelper.setAttribute(request, Constants.NAVIGATOR_KIND,"/desktop");
			return "/desktop"+url;
		}
	}
	
	public static boolean isMobile(HttpServletRequest request) {
		String userAgent = request.getHeader( "user-agent").toLowerCase();
		if (userAgent.contains("iphone")) {
			return true;
		} else {
			return false;
		}
	}
}
